/*------------------------------------------------
<> Skype Connectivity Layer header
<> 2008.12.02 - Robert Vanca
<> v0.1
--------------------------------------------------*/
#pragma once
#ifndef _BASELIB_SKYPE_CL_H
#define _BASELIB_SKYPE_CL_H

#include <windows.h>

#define LOGGING true

struct msgContainer
{
	string chat_id;
	string message_owner;
	string message;
	string user;

public:
	bool inline is_complete() {return (chat_id.length() && message_owner.length() && message.length() && user.length());}
};

class SKYPE_CL
{
	enum {
		SKYPECONTROLAPI_ATTACH_SUCCESS=0,								// Client is successfully attached and API window handle can be found in wParam parameter
		SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION=1,					// Skype has acknowledged connection request and is waiting for confirmation from the user.
		SKYPECONTROLAPI_ATTACH_REFUSED=2,								// User has explicitly denied access to client
		SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE=3,							// API is not available at the moment. For example, this happens when no user is currently logged in.
		SKYPECONTROLAPI_ATTACH_API_AVAILABLE=0x8001
	};

private:
	unsigned int msgSkypeControlAPIDiscover; //send
	unsigned int msgSkypeControlAPIAttach; //return
	HWND SkypeHWND;
	HWND OwnHWND;
	std::ofstream logfile;
	
	vector<string> allowedusers;
	vector<string> chatlist;
	map<int,msgContainer> messagequeue;

public:
	SKYPE_CL(HWND hWnd);
	~SKYPE_CL();

	//base functions
	void SkypeLog(const char* param);
	bool ReadAllowedList();
	void PrintAllowedUsers();
	LRESULT	 MainMsgProc(UINT uiMessage, WPARAM wParam, LPARAM lParam);
	bool ConnectionKeepAlive();
	bool UserIsAllowed(string user);

	//skype connection layer
	bool SkypeConnected();
	void SkypeDisconnect();
	void SendSkypeMessage (const char *command);

	//messsage processing
	void ParseMsg(string command);
	void EscapeString(string& message);
	void Split_at_char(vector<string>& substrings,const string& mainstring,char separator);
	void Split_MSG_at_char(vector<string>& substrings,const string& mainstring,char separator,int depth);
	void Process_Commands(const string& mainstring);
	string GetCommand(const string& mainstring);
	string ProcessMessage(string& message);
	int MessagesCompleted();

	//skype commands
	void SendChatMessage(const string& chat_id,const string& message);
	void GetChatID(const string& message_id);
	void GetMessageOwner(const string& message_id);
	void GetMessageBody(const string& message_id);
	void GetUser(const string& message_id);

	
};


#endif //_BASELIB_SKYPE_CL_H